package cn.wsw.hrm.controller;

import cn.wsw.hrm.util.AjaxResult;
import cn.wsw.hrm.util.RedisUtil;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cache")
public class RedisController{
    @PostMapping
    public AjaxResult add(
            @RequestParam(value = "key",required = true) String key,
            @RequestParam(value = "value",required = true) String value)
    {
        try
        {
            Boolean aBoolean = RedisUtil.INSTANCE.set(key, value);
            System.out.println(aBoolean);
            System.out.println("rrrrrrrrrrrrr");
            return AjaxResult.me().setSuccess(aBoolean);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("添加失败");
        }
    }
//
    @PutMapping
    AjaxResult addForTime(@RequestParam(value = "key",required = true) String key
            ,@RequestParam(value = "value",required = true) String value,@RequestParam(value = "time",required = true)Integer time){
        try
        {
            RedisUtil.INSTANCE.set(key,value,time);
            return AjaxResult.me();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("添加失败");
        }
    }
//
//    @DeleteMapping
//    public AjaxResult del(@RequestParam(value = "key",required = true) String key)
//    {
//        try
//        {
//            RedisUtil.INSTANCE.del(key);
//            return AjaxResult.me();
//        }catch (Exception e){
//            e.printStackTrace();
//            return AjaxResult.me().setSuccess(false).setMessage("删除失败");
//        }
//    }
//
    @GetMapping
    public String get(@RequestParam(value = "key",required = true) String key)
    {
        try
        {
            return RedisUtil.INSTANCE.get(key);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }


    //设置验证码过期时间

}
